package com.maguangwu.controller;

import com.maguangwu.entity.Result;
import com.maguangwu.exception.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author mgw
 * @create 2021/10/30 22:06
 */
@RestControllerAdvice
public class MyExceptionAdvice {
    private static final Logger log = LoggerFactory.getLogger(MyException.class);

    @ExceptionHandler(MyException.class)
    public Result handlerMyException(MyException e) {
        System.out.println("用户行为不规范");
        log.info("用户行为不规范");
        return new Result(false, e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result handException(Exception e) {
        log.info("发生位置异常了", e);
        return new Result(false, e.getMessage());
    }
}
